<!--
 * @Descripttion: 搜索工具类-保养项目
 * @LastEditors: xzh
 * @LastEditTime: 2023-09-09 15:45:41
-->
<template>
  <el-col :span="11">
    <el-input
      v-model="searchData.keyWord"
      clearable
      size="large"
      :placeholder="$t('page.moldUpkeepArr.upkeepItemArr.searchCondition')"
    />
  </el-col>
  <el-col :span="11">
    <el-select
      v-model="searchData.typeId"
      size="large"
      :placeholder="$t('common.select') + $t('page.moldManageArr.moldType')"
    >
      <el-option
        v-for="item in searchToolParam.moldTypeArr"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </el-col>
</template>

<script setup lang="ts">
import { ref, reactive, toRef, onBeforeMount } from "vue";
import { object_Inf } from "@/utils/typings/index.type";
import Dile_Methods from "@/utils/methods";
import Dile_APi from "@/api";
const props = defineProps({
  //搜索数据
  searchData: {
    type: Object,
    requited: true,
    default: {},
  },
});

/**
 * @Author: xzh
 * @Descripttion: 模具检索参数
 * @Param:
 */
let searchToolParam = reactive<object_Inf>({
  moldTypeArr: [],
});

/**
 * @Author: xzh
 * @Descripttion: 默认搜索数据
 * @Param:
 */
let defaultData = () => ({
  keyWord: "",
  typeId: "", //模具类型
});
/**
 * @Author: xzh
 * @Descripttion: 初始化
 * @Param:
 */
onBeforeMount(() => {
  reset();
  //加载搜索资源
  initSearchToolResource();
});

/**
 * @Author: xzh
 * @Descripttion: 加载搜索资源
 * @Param:
 */
let initSearchToolResource = async () => {
  await initMoldTypeResource();
};

/**
 * @Author: xzh
 * @Descripttion: 加载模具类型资源
 * @Param:
 */
let initMoldTypeResource = async () => {
  let moldTypeArr = toRef(searchToolParam, "moldTypeArr");
  //加载所有模具状态
  moldTypeArr.value = Dile_Methods.filterDataArr(
    (await Dile_APi.getMoldTypeList()).map((type: object_Inf) => ({
      value: type.id,
      label: type.name,
    }))
  );
};

/**
 * @Author: xzh
 * @Descripttion: 重置
 * @Param:
 */
let reset = () => {
  Object.assign(props.searchData, defaultData());
};

defineExpose({
  reset,
});
</script>
<style lang="scss" scoped></style>
